package com.wx.tnsenterprise.controller;

import com.github.pagehelper.PageInfo;
import com.wx.common.api.CommonResult;
import com.wx.tnsenterprise.model.dto.FunnelRecDto;
import com.wx.tnsenterprise.model.dto.PageDto;
import com.wx.tnsenterprise.model.po.EnterprisePo;
import com.wx.tnsenterprise.model.po.HrPo;
import com.wx.tnsenterprise.model.po.RecruitPo;
import com.wx.tnsenterprise.model.vo.RecDetailVo;
import com.wx.tnsenterprise.model.vo.RecNavVo;
import com.wx.tnsenterprise.model.vo.RecruitHotVo;
import com.wx.tnsenterprise.model.dto.RecruitDto;
import com.wx.tnsenterprise.service.RecruitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 林建权
 * @version 1.0
 * @date 2020/7/28 16:49
 */
//招聘信息接口
@CrossOrigin
@RestController
@RequestMapping("/recruit")
@Api(tags = "招聘信息接口")
public class RecruitController {

    @Autowired
    private RecruitService recruitService;

    //前端需求
    @PostMapping("/insertByRecVo")
    @ApiOperation(value = "添加招聘", notes = "添加招聘")
    public CommonResult insertByRecVo(@RequestBody RecruitDto recruitDto) {
        int result = 0;
        try{
            result = recruitService.insertByRecVo(recruitDto);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("添加失败！");
        }
        return CommonResult.success("添加"+result+"条数据成功！");
    }

    //首页热招
    @GetMapping("/findHotRec")
    @ApiOperation(value = "查询首页热门招聘", notes = "查询首页热门招聘")
    public CommonResult findHotRec(@RequestParam Integer length) {
        List<RecruitHotVo> result =null;
        try{
            result = recruitService.findHotRec(length);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("查询失败！");
        }
        return CommonResult.success(result);
    }

    //职位栏目下招聘
    @PostMapping("/findRecByFunnel")
    @ApiOperation(value = "职位栏目下招聘", notes = "职位栏目下招聘")
    public CommonResult<PageInfo<RecNavVo>> findRecByFunnel(@RequestBody FunnelRecDto funnelRecDto) {
        PageInfo<RecNavVo> result =null;
        try{
            result = recruitService.findRecByFunnel(funnelRecDto);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("查询失败！");
        }
        return CommonResult.success(result);
    }

    //招聘栏目下热门城市
    @GetMapping("/findRecHotCity")
    @ApiOperation(value = "招聘栏目下热门城市", notes = "招聘栏目下热门城市")
    public CommonResult findRecHotCity(@RequestParam Integer length) {
        List<String> result =null;
        try{
            result = recruitService.findRecHotCity(length);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("查询失败！");
        }
        return CommonResult.success(result);
    }

    //招聘栏目下热门职位
    @GetMapping("/findRecHotJob")
    @ApiOperation(value = "招聘栏目下热门职位", notes = "招聘栏目下热门职位")
    public CommonResult findRecHotJob(@RequestParam Integer length) {
        List<String> result =null;
        try{
            result = recruitService.findRecHotJob(length);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("查询失败！");
        }
        return CommonResult.success(result);
    }

    //职位详情页
    @GetMapping("/RecDetail")
    @ApiOperation(value = "职位详情页", notes = "职位详情页")
    public CommonResult<RecDetailVo> RecDetail(@RequestParam Integer id) {
        RecDetailVo result = null;
        try{
            result = recruitService.recDetail(id);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("查询失败！");
        }
        return CommonResult.success(result);
    }

    //获取全部招聘信息
    @GetMapping("/all")
    @ApiOperation(value = "获取全部招聘信息",notes = "获取全部招聘信息")
    public CommonResult<List<RecruitPo>> findAll(){
        List<RecruitPo> list = null;
        try{
           list = recruitService.findAll();
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("查询全部招聘数据失败");
        }
        return CommonResult.success(list);
    }

    //获取全部招聘信息（分页）
    @PostMapping("/allPageInfo")
    @ApiOperation(value = "获取全部招聘信息（分页）",notes = "获取全部招聘信息（分页）")
    public CommonResult<PageInfo<RecruitPo>> findAllPageInfo(@RequestBody PageDto pageDto){
        PageInfo<RecruitPo> list = null;
        try{
            list = recruitService.findAllPageInfo(pageDto);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("查询全部招聘数据失败");
        }
        return CommonResult.success(list);
    }

    //获取单个招聘信息
    @GetMapping("/findById")
    @ApiOperation(value = "获取单个招聘信息",notes = "获取单个招聘信息")
    public CommonResult<RecruitPo> findById(@RequestParam Integer id){
        RecruitPo result = null;
        try{
            result = recruitService.findById(id);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("获取单个招聘信息失败");
        }
        return CommonResult.success(result);
    }

    //测试Service接口
    @PostMapping("/insert")
    @ApiOperation(value = "添加招聘", notes = "添加招聘")
    public CommonResult insert(@RequestBody RecruitPo recruitPo) {
        int result = 0;
        try{
            result = recruitService.insert(recruitPo);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("添加失败！");
        }
        return CommonResult.success("添加"+result+"条数据成功！");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改招聘数据", notes = "修改招聘数据")
    public CommonResult update(@RequestBody RecruitPo recruitPo) {
        int result = 0;
        try{
            result = recruitService.update(recruitPo);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.failed("修改失败！");
        }
        return CommonResult.success("修改"+result+"条数据成功！");
    }

    @GetMapping("/delete")
    @ApiOperation(value = "删除招聘数据", notes = "删除招聘数据")
    public CommonResult delete(@RequestParam Integer id) {
        int result = 0;
        try{
            result = recruitService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            return CommonResult.success("删除失败！");
        }
        return CommonResult.success("删除"+result+"条数据成功！");
    }
}
